package ru.urfc.portal.ui.client.renderers;

import ru.urfc.portal.ui.client.EnumRegistry;
import ru.urfc.portal.ui.client.Style;
import ru.urfc.portal.ui.client.Utils;
import ru.urfc.portal.ui.client.descriptor.GridField;
import ru.urfc.portal.ui.client.model.catalogs.booleans.BooleanCatalogItem;
import ru.urfc.portal.ui.client.renderers.colorers.BooleanCatalogItemColorer;

import com.extjs.gxt.ui.client.data.ModelData;
import com.google.gwt.dom.client.Element;

public class BooleanCatalogItemRenderer extends CatalogItemRenderer {

	protected Class<? extends BooleanCatalogItem> klass;
	
	public BooleanCatalogItemRenderer(GridField codeField, 
			Class<? extends BooleanCatalogItem> klass, Element element, Style style) {
		super(codeField, element, new BooleanCatalogItemColorer(codeField, klass, element, style));
		this.klass = klass;
	}
	
	@Override
	public String render(ModelData modelData) {
		Boolean code = field.getValue(modelData);
		BooleanCatalogItem item = EnumRegistry.getCatalogItem(klass, code);
		return renderForCell? Utils.decapitalize(item.getText()): Utils.capitalize(item.getFullText());
	}

}
